﻿using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace WebApiExtend.Middleware
{
    /// <summary>
    /// 日志管道
    /// </summary>
    public class LogMiddleware : BaseMiddleware
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="next"></param>
        public LogMiddleware(RequestDelegate next) : base(next)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext httpContext)
        {
            var entity = base.InitLogModel(httpContext);
            await _next.Invoke(httpContext);
            await this.AddLog(entity);
        }
    }
}
